import { createRouter, createWebHistory } from "vue-router";
import { Home, News, About, NewsContent } from "../views";
const router = createRouter({
  routes: [
    {
      name: "firstPage",
      path: "/home",
      component: Home,
    },
    {
      path: "/news",
      component: News,
      children: [
        {
          name: "newsDetail",
          path: "detail/:id",
          component: NewsContent,
          // props 设置为true，能将 id 加入到 NewsContent 组件的 props 中
          // props: true,
          props: (option) => {
            return {
              id: option.params.id,
              title: option.query.title,
              content: option.query.content,
            };
          },
        },
      ],
    },
    {
      path: "/about",
      component: About,
    },
    {
      path: "/",
      redirect: "/home",
    },
  ],
  history: createWebHistory(),
});

export default router;
